window.hzmr = window.hzmr || []; window.hzmr.push("widgets:1889");

(function() {
	function createIFrame(width, height,scrolling) {
		if (scrolling==undefined) scrolling = "no";
		var iframeElem = document.createElement('iframe');
		iframeElem.setAttribute("scrolling",scrolling);
		iframeElem.allowTransparency = true;
		iframeElem.border = 0;
		iframeElem.frameBorder = 0;
		iframeElem.style.border = 'none';
		iframeElem.width = width;
		iframeElem.height = height;
		return iframeElem;
	}

	function containsClassName(elem, className) {
		var classNames = elem.className.split(' ');
		for(var i=0; i<classNames.length; i++) {
			if(className == classNames[i]) {
				return true;
			}
		}
		return false;
	}
	
	function processWidgets(domId) {
		var links = [];
		if(typeof domId == 'string') {
			if(domId.charAt(0) == '#') {
				domId = domId.substr(1);
			}
			var elem = document.getElementById(domId);
			if(elem) {
				links.push(elem);
			}
		} else if(typeof domId != 'undefined' && ('nodeName' in domId)) {
			links.push(domId);
		} else {
			links = (jQuery)('#shampoo-widget');
		}
		var linkURL = links.attr('data-url');
		var title = links.attr('data-title');
		var description = links.attr('data-desc');
		var dataWidth = links.attr('data-width');
		var dataHeight = links.attr('data-height');
		var dataParam = links.attr('data-param');
		var hzID = links.attr('data-hzid');
		var whiteBg = links.attr('data-whitebg');
		var identifier ='' + Math.floor(Math.random()*1000000);
		links.id = 'hzbtn' + identifier;
		var referer = document.location.href;
		var pid = new Date().getTime() + '' + Math.floor(Math.random()*1000000);
		var buttonWidth = '100%';
		var iframeSrc = linkURL;
		var scrolling = links.attr('data-scroll');
		iframeSrc += '?t=embed&ref=' + encodeURIComponent(referer);
		iframeSrc += '&pid=' + encodeURIComponent(pid);
		
		if(title) {
			iframeSrc += '&title=' + encodeURIComponent(title);
		}
		if(description) {
			iframeSrc += '&description=' + encodeURIComponent(description);
		}
		if(dataParam) {
			iframeSrc += '&' + encodeURIComponent(dataParam);
		}
		if(whiteBg) {
			var whiteBgValue = 0;
			if(String(whiteBg) == '1' || whiteBg.toLowerCase() == 'true') {
				whiteBgValue = 2;
			} else if(String(whiteBg) == '0' || whiteBg.toLowerCase() == 'false') {
				whiteBgValue = 1;
			}
			iframeSrc += '&whiteBg=' + encodeURIComponent(whiteBgValue);
		}
		if(hzID) {
			iframeSrc += '&hzid=' + encodeURIComponent(hzID);
		}
		
		if (dataHeight==undefined || (jQuery).trim(dataHeight)=="")
			dataHeight = '500';
		if (dataWidth==undefined || (jQuery).trim(dataWidth)=="")
			dataWidth = '100%';
		var iframeElem = createIFrame(dataWidth, dataHeight,scrolling);
		iframeElem.src = iframeSrc;
		$('#shampoo-widget').html(iframeElem);
	}

	window.shampoo = window.shampoo || {};
	window.shampoo.processWidgets = processWidgets;
	processWidgets();
})();